<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>ProductProfile-list</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/lib/layuimini2/lib/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="/lib/layuimini2/css/public.css" media="all">
	<link rel="stylesheet" href="/css/common.css" media="all">
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="" lay-filter="search-form">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">名称</label>
							<div class="layui-input-inline">
								<input type="text" name="name" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">编码</label>
							<div class="layui-input-inline">
								<input type="text" name="code" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">是否医保</label>
							<div class="layui-input-inline" style="width: 100px">
								<select name="isMedical">
									<option value="">不限</option>
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">是否基药</label>
							<div class="layui-input-inline" style="width: 100px">
								<select name="isBasicDrug">
									<option value="">不限</option>
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">有效期（月）</label>
							<div class="layui-input-inline">
								<input type="text" name="expiryDate" autocomplete="off" lay-verify="positiveInteger"
								       class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary" lay-submit
							        lay-filter="data-search-btn"><i class="layui-icon layui-icon-search"></i> 搜 索
							</button>
							<button type="button" class="layui-btn layui-btn-normal" id="add">
								<i class="layui-icon layui-icon-add-1"></i>添加
							</button>
							<button type="button" class="layui-btn" id="import">
								<i class="layui-icon layui-icon-upload"></i>导入
							</button>
							<button type="button" class="layui-btn layui-btn-primary" id="export">
								<i class="layui-icon layui-icon-download-circle"></i>导出
							</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>

		<table class="layui-hide" id="dataTableId" lay-filter="dataTableFilter"></table>

		<script type="text/html" id="dataTableBar">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="policy">销售政策</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>

	</div>
</div>
<form class="layui-form layui-form-pane" id="layerForm" lay-filter="dataForm" style="display: none;padding:5px">
	<input type="hidden" name="id" id="id"/>
	<div class="layui-form-item" widthoffset="10">
		<div class="layui-inline">
			<label class="layui-form-label">编码</label>
			<div class="layui-input-block col6">
				<input type="text" name="code" placeholder="请输入产品编码" lay-verify="required" lay-reqtext="请填写产品编码"
				       class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">名称</label>
			<div class="layui-input-block col6">
				<input type="text" name="name" placeholder="请输入产品名称" lay-verify="required" lay-reqtext="请填写产品名称"
				       class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item" widthoffset="10">
		<div class="layui-inline">
			<label class="layui-form-label">产品单位</label>
			<div class="layui-input-block col6">
				<select name="unit" id="unitFrm">
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">产品规格</label>
			<div class="layui-input-block col6">
				<select name="spec" id="specFrm">
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item" widthoffset="10">
		<div class="layui-inline">
			<label class="layui-form-label">产品类别</label>
			<div class="layui-input-block col6">
				<select name="type" id="typeFrm">
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">区域</label>
			<div class="layui-input-block col6">
				<div id="area"></div>
			</div>
		</div>
	</div>
	<div class="layui-form-item" widthoffset="10">
		<div class="layui-inline">
			<label class="layui-form-label">是否医保</label>
			<div class="layui-input-block col6">
				<select name="isMedical">
					<option value="0">否</option>
					<option value="1">是</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">是否基药</label>
			<div class="layui-input-block col6">
				<select name="isBasicDrug">
					<option value="0">否</option>
					<option value="1">是</option>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item" widthoffset="10">
		<div class="layui-inline">
			<label class="layui-form-label">件装量</label>
			<div class="layui-input-block col6">
				<input type="text" name="capacity" placeholder="请输入件装量" lay-verify="positiveInteger"
				       class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">有效期（月）</label>
			<div class="layui-input-block col6">
				<input type="text" name="expiryDate" placeholder="请输入有效期（月）" lay-verify="positiveInteger"
				       class="layui-input">
			</div>
		</div>
	</div>
	</div>
	<div class="layui-form-item btns">
		<div class="layui-input-block">
			<button id="submitBtn" class="layui-btn layui-btn-radius" lay-submit lay-filter="layerForm">确定</button>
			<button class="layui-btn layui-btn-radius layui-btn-primary cancel" type="button">取消</button>
		</div>
	</div>
</form>

<script src="/lib/layuimini2/lib/layui/layui.js" charset="utf-8"></script>
<script src="/js/common.js" charset="utf-8"></script>
<script src="/lib/layuimini2/js/lay-module/xmSelect/xm-select.js"></script>
<script src="/lib/layuimini2/js/lay-config.js" charset="utf-8"></script>
<script>
	layui.use(['form', 'table', 'upload', 'miniTab'], function () {
		var $ = layui.jquery,
			form = verifyForm(layui.form),
			miniTab = layui.miniTab,
			table = layui.table;
		var layerFormIdx;
		var isMedicalProp = ["否", "是"];

		$(".btns .cancel").click(function () {
			layer.closeAll();
		});

		$("#export").click(function () {
			window.open("/productProfile/export?" + json2param(form.val("search-form")));
		});

		var area, areaData;
		getAreaTreeAndRend(layui, "#area", function (areaDom, data) {
			area = areaDom;
			areaData = data;
		}, true);

		var keys = [];
		keys.push(PRODUCT_SPEC_KEY);
		keys.push(PRODUCT_TYPE_KEY);
		keys.push(PRODUCT_UNIT_KEY);

		myAjax($, layer, {
			url: "/dict/listByKeys",
			type: 'GET',
			data: {
				keys: keys.join(",")
			},
			dataType: "json",
			success: function (d, s) {
				$("#specFrm").html(d.data[PRODUCT_SPEC_KEY]);
				$("#typeFrm").html(d.data[PRODUCT_TYPE_KEY]);
				$("#unitFrm").html(d.data[PRODUCT_UNIT_KEY]);
				form.render('select');
			}
		});

		var dataTable = myTableRend(table, layer, {
			elem: '#dataTableId',
			url: '/productProfile/listByPage',
			//toolbar: '#toolbarDemo',
			// defaultToolbar: ['filter', 'exports', 'print', {
			// 	title: '提示',
			// 	layEvent: 'LAYTABLE_TIPS',
			// 	icon: 'layui-icon-tips'
			// }],
			cols: [[
				{field: 'code', title: '产品编码', align: "center"},
				{field: 'name', title: '产品名称', align: "center"},
				{field: 'unitStr', title: '产品单位', align: "center", width: 90},
				{field: 'specStr', title: '产品规格', align: "center"},
				{field: 'typeStr', title: '产品类别', align: "center", width: 100},
				{field: 'capacity', title: '件装量', align: "center"},
				{field: 'expiryDate', title: '有效期（月）', align: "center", width: 115},
				{
					field: 'isMedical', title: '是否医保', width: 90, align: "center", templet: function (d) {
						return isMedicalProp[d.isMedical];
					}
				},
				{
					field: 'isBasicDrug', title: '是否基药', width: 90, align: "center", templet: function (d) {
						return YES_NO_PROP[d.isBasicDrug];
					}
				},
				{field: 'areaIdStr', title: '区域', align: "center", width: 120},
				{title: '操作', width: 170, toolbar: '#dataTableBar', align: "center", fixed: "right"}
			]],
			limits: [10, 15, 20, 25, 50, 100],
			limit: 15,
			page: true,
			skin: 'line'
		});

		//初始化导入
		initImport(layui, {
			templet: "/productProfile/importTemplate",
			import: "/productProfile/importData",
			table: dataTable
		});

		// 监听搜索操作
		form.on('submit(data-search-btn)', function (data) {
			//执行搜索重载
			table.reload('dataTableId', {
				page: {
					curr: 1
				}
				, where: data.field
			});

			return false;
		});

		$("#add").click(function () {
			$("#layerForm")[0].reset();
			$("#id").val("");
			area.setValue([]);
			layerFormIdx = layerForm(layer, $, {
				title: '添加产品',
				content: $("#layerForm"),
				type: 1,
				area: ["600px", "450px"],
				shade: 0.2,
				maxmin: true,
				shadeClose: false,
			});
			submitLayerForm("layerForm", '/productProfile/add', "添加", dataTable, layerFormIdx, layui);
		});


		table.on('tool(dataTableFilter)', function (obj) {
			if (obj.event === 'edit') {
				$("#layerForm")[0].reset();
				form.val("dataForm", obj.data);
				area.setValue([findTreeNode(areaData, obj.data.areaId)]);
				layerFormIdx = layerForm(layer, $, {
					title: '修改产品',
					content: $("#layerForm"),
					type: 1,
					area: ["600px", "400px"],
					shade: 0.2,
					maxmin: true,
					shadeClose: false,
				});
				submitLayerForm("layerForm", '/productProfile/edit', "更新", dataTable, layerFormIdx, layui);
			} else if (obj.event == 'del') {
				layer.confirm('确定删除吗？', function (index) {
					myAjax($, layer, {
						url: "/productProfile/del",
						type: 'POST',
						data: {
							id: obj.data.id
						},
						dataType: "json",
						success: function (d, s) {
							if (d.code == 1) {
								layer.msg('删除成功', {icon: 1, time: 1500});
								dataTable.reload();
							}
						}
					});
					layer.close(index);
				});
			} else if (obj.event == 'policy') {
				// 打开新的窗口
				miniTab.openNewTabByIframe({
					href: "page/SalesPolicy-list.html?pid=" + obj.data.id,
					title: "产品销售政策",
				});
			}
		});

	});

</script>

</body>
</html>